package com.zygh.lz.controller.app;

import com.alibaba.fastjson.JSONObject;
import com.zygh.lz.entity.Staff;
import com.zygh.lz.service.SectionService;
import com.zygh.lz.service.SignService;
import com.zygh.lz.service.StaffService;
import com.zygh.lz.service.XlevelserviceService;
import com.zygh.lz.stapprove.InBean;
import com.zygh.lz.stapprove.OutBean;
import com.zygh.lz.stapprove.OutBeanUtil;
import com.zygh.lz.stapprove.ViLog;
import com.zygh.lz.vo.ResultBeans;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "APP日常勤务/特殊勤务模块", description = "AppServiceDutyController")
@RestController
public class AppServiceDutyController {
    @Resource
    private SectionService sectionService;
    @Resource
    private XlevelserviceService xlevelserviceService;
    @Resource
    private SignService signService;
    @Resource
    private StaffService staffService;


    @PostMapping("findSectionById")
    @ApiOperation("日常勤务列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "sectionId", value = "大队id", dataType = "int", required = true),
            @ApiImplicitParam(name = "policeNumber", value = "警号", dataType = "string", required = true)})
    @ViLog(logType = "1", module = "日常勤务>大队下岗位列表")
    public OutBean findSectionById(@RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);

        int sectionId = Integer.parseInt(jsonObject.getString("sectionId"));
        String policeNumber = jsonObject.getString("policeNumber");
        //判断人员是不是到支队了
        if (sectionId == 74) {
            List<Integer> list = sectionService.findSectionNum(sectionId);
            Staff staff = staffService.selectStaffByNum(policeNumber);
            if (list.indexOf(staff.getSysSectionId()) != -1) {
                sectionId = staff.getSysSectionId();
            }
        }

        ResultBeans resultBeans = sectionService.findSectionById(sectionId, policeNumber);
        return OutBeanUtil.resSuc(resultBeans, inBean);
    }



    @ApiOperation("app日常勤务下方签到状态栏")
    @ApiImplicitParam(name = "warningsignal", value = "警号", dataType = "String", required = true)
    @PostMapping("findPostStatus")
    public OutBean findPostStatus(@RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);
        ResultBeans resultBeans = signService.findPostStatu(jsonObject.getString("warningsignal"));
        return OutBeanUtil.resSuc(resultBeans, inBean);
    }

    @PostMapping("findSpecialById")
    @ApiOperation("特殊勤务列表")
    @ViLog(logType = "1", module = "特殊勤务》签到按大队显示特殊勤务")
    public OutBean findSpecialById(@RequestBody(required = false) InBean inBean) {
        JSONObject jsonObject = inBean.convertObj(JSONObject.class);
        ResultBeans resultBeans = xlevelserviceService.findSpecialById(Integer.valueOf(jsonObject.getString("sectionId")), jsonObject.getString("warningsignal"));
        return OutBeanUtil.resSuc(resultBeans, inBean);
    }


}
